// 迭代器iterator
const iterator = {
    next: () => ({
        done: true,
        value: 0
    })
}

const names = [111, 222, 333]
// 创建数组的迭代器
// const namesIterator = {
//     next: () => {
//         return { done: false, value: 111 }
//         return { done: false, value: 222 }
//         return { done: false, value: 333 }
//         return { done: true, value: undefined }
//     }
// }
let index = 0
const namesIterator = {
    next: () => {
        if (index < names.length) {
            return { done: false, value: names[index++] }
        } else {
            return { done: true, value: undefined }
        }
    }
}
let result = namesIterator.next();
while (!result.done) {
 console.log(result.value); 
 result = namesIterator.next();
}
